{include file="common/top" /}
<style>
html{
	background: #ffffff;
}
</style>
<form class="layui-form " action="" style="    background: #fff;">
	<div class="layui-form-item">
		<label class="layui-form-label">订单号：</label>
		<div class="layui-col-xs4">
			<input type="text" value="{$rs.order_num}" readonly="readonly" lay-verify="required" autocomplete="off" class="layui-input">
		</div>
		<label class="layui-form-label">销售时间：</label>
		<div class="layui-col-xs4">
			<input type="text" name="sell_time" id="date" value="{:date('Y-m-d',$rs['sell_time'])}"  lay-verify="required" autocomplete="off" placeholder="yyyy-mm-dd" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">客户名称：</label>
		<div class="layui-col-xs4">
			<select name="customer_id" lay-verify="required" lay-search=""  lay-verify="required" autocomplete="off">
				<option value="">直接选择或搜索选择</option>
				{volist name="Customer_list" id='pt'}
					<option value="{$pt.id}" {eq name ="rs.customer_id" value="$pt.id"}selected{/eq}>{$pt.name}</option>
				{/volist}
	        </select>
		</div>
		<label class="layui-form-label">媒介人员：</label>
		<div class="layui-col-xs4">
			<select name="media_id" lay-verify="required" lay-search=""  lay-verify="required" autocomplete="off">
				<option value="">直接选择或搜索选择</option>
				{volist name="media_list" id='m'}
					<option value="{$m.id}" {eq name ="rs.media_id" value="$m.id"}selected{/eq} >{$m.username}</option>
				{/volist}
	        </select>
		</div>
	</div>
	
	<div class="layui-form-item">
		
		<label class="layui-form-label">销售单价：</label>
		<div class="layui-col-xs4">
			<input type="text" name="sell" value="{$rs.sell}" lay-verify="required" autocomplete="off" placeholder="销售单价（元）" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">销售数量：</label>
		<div class="layui-col-xs4">
			<input type="number" name="num" value="{$rs.num}" lay-verify="required" autocomplete="off" placeholder="销售数量" class="layui-input" oninput="get_total()">
		</div>
		<label class="layui-form-label">销售总价：</label>
		<div class="layui-col-xs4">
			<input type="text" name="total" value="{$rs.total}" lay-verify="required" autocomplete="off" placeholder="销售总价（元）" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">销售点：</label>
		<div class="layui-col-xs4">
			<input type="text" name="rebates" value="{$rs.rebates}" lay-verify="required" autocomplete="off" placeholder="销售点比例（%）" class="layui-input">
		</div>
		<label class="layui-form-label">销售类型：</label>
		<div class="layui-col-xs4">
			<select name="type" lay-verify="required" lay-search=""  lay-verify="required" autocomplete="off">
				<option value="">直接选择或搜索选择</option>
				<option value="1"  {eq name ="rs.type" value="1"}selected{/eq} >表单</option>
				<option value="2" {eq name ="rs.type" value="2"}selected{/eq} >视频</option>
	        </select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">上传凭证：</label>
		<div class="layui-col-xs4">
			<div class="layui-upload-drag" id="test10">
			  	<i class="layui-icon"></i>
			  	<p>点击上传，或将文件拖拽到此处</p>
			  	<div class="layui-hide" id="uploadDemoView"  style="{:$rs['pinzheng']?'display:block !important;':''}">
			  		<hr>
			    	<img src="{$rs.pinzheng}" alt="上传成功后渲染" style="max-width: 196px">
			  	</div>
			</div>
		</div>
		
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">备注：</label>
		<div class="layui-col-xs8">
			<textarea name="note" autocomplete="off" placeholder="请输入渠道详细备注" class="layui-textarea">{$rs.note}</textarea>
		</div>
	</div>
	
	<hr />
	<div class="layui-form-item">
		<div class="layui-input-block">
			<input type="hidden" name="pinzheng" value="{$rs.pinzheng}"  >
			<input type="hidden" name="id" value="{$rs.id}"  >
			<button class="layui-btn"  lay-submit="" lay-filter="demo1">添加</button>
		</div>
	</div>
	
</form>
{include file="common/footer" /}
<script>
	layui.use(['form', 'layedit', 'laydate','upload'], function(){
		  var form = layui.form ,layer = layui.layer, laydate = layui.laydate,upload = layui.upload,$ = layui.jquery;
		  laydate.render({
			    elem: '#date', //指定元素
			  });
		  //监听提交
		  form.on('submit(demo1)', function(data){
			var articleFrom = data.field;
			layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
			$.post("{:url('save_order')}?t=json",articleFrom,function(data){
				layer.closeAll();
				if (data['code'] == 1) { 
					var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index1); //再执行关闭 
					//父页面数据 ，重新加载
					parent.get_load(data['msg']);

				} else {
					layer.msg(data['msg'], { icon : 5 });
				}
			});
			
			return false;
		  });
		//拖拽上传
		  upload.render({
		    elem: '#test10'
		    ,url: '{:url("Upload/index")}' //改成您自己的上传接口
		    ,exts: 'jpg|png|jpeg|gif'
	    	,choose: function(obj){
	    		layer.load(1, { shade : [ 0.5, '#676a6c' ] });
	    	}
		    ,done: function(res){
		    	layer.closeAll();
		    	if(res.code == 0){
		    		layer.msg('上传成功');
				    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data);
				    $("input[name=pinzheng]").val(res.data);
		    	}else{
		    		layer.msg(res.msg);
		    	}
		      
		      //console.log(res)
		    }
		  });
		});
	function get_total(){
		var sell = $("input[name=sell]").val();
		var num = $("input[name=num]").val();
		if(sell <= 0){
			layer.msg('请输入有效的销售单价', { icon : 5 });
			return false;
		}
		var ta = num * sell;
		$("input[name=total]").val(ta);
	}
</script>
